
tpoints=[-48 -24 6 18 24 48];

fract_running=NaN(6,31);
fract_running_light=NaN(6,31);
fract_running_dark=NaN(6,31);
for ind=1:31
    for knd=1:length(hom_data(ind).raw_data)
        t_ind=find(hom_data(ind).raw_data(knd).timepoint==tpoints);
        fract_running(t_ind,ind)=sum(abs(hom_data(ind).raw_data(knd).act_code)>1)/sum(abs(hom_data(ind).raw_data(knd).act_code)>0);
        fract_running_light(t_ind,ind)=sum((hom_data(ind).raw_data(knd).act_code)>1)/sum((hom_data(ind).raw_data(knd).act_code)>0);
        fract_running_dark(t_ind,ind)=sum((hom_data(ind).raw_data(knd).act_code)<-1)/sum((hom_data(ind).raw_data(knd).act_code)<0);
    end
end
        


ncl=nanmean(nanmean(fract_running_light(1:2,1:17)'));
ncc=nanmean(nanmean(fract_running_light(1:2,18:end)'));

figure;
hold on
plot(tpoints(1:2),nanmean(fract_running_light(1:2,1:17)')/ncl,'k','linewidth',2)
plot(tpoints(3:5),nanmean(fract_running_light(3:5,1:17)')/ncl,'k','linewidth',2)
plot(tpoints(1:5),nanmean(fract_running_light(1:5,1:17)')/ncl,'k.','markersize',15)
for ind=1:5
    plot([1 1]*tpoints(ind),nanmean(fract_running_light(ind,1:17)')/ncl+[nanstd(fract_running_light(ind,1:17)')/sqrt(17) -nanstd(fract_running_light(ind,1:17)')/sqrt(17)]/ncl,'k','linewidth',2)
end

plot(tpoints(1:2),nanmean(fract_running_light(1:2,18:end)')/ncc,'r','linewidth',2)
plot(tpoints(3:5),nanmean(fract_running_light(3:5,18:end)')/ncc,'r','linewidth',2)
plot(tpoints(1:5),nanmean(fract_running_light(1:5,18:end)')/ncc,'r.','markersize',15)
for ind=1:5
    plot([1 1]*tpoints(ind),nanmean(fract_running_light(ind,18:end)')/ncc+[nanstd(fract_running_light(ind,18:end)')/sqrt(14) -nanstd(fract_running_light(ind,18:end)')/sqrt(17)]/ncc,'r','linewidth',2)
end

% plot(tpoints,nanmean(fract_running(:,18:end)')+nanstd(fract_running(:,18:end)')/sqrt(14),'r','linewidth',1)
% plot(tpoints,nanmean(fract_running(:,18:end)')-nanstd(fract_running(:,18:end)')/sqrt(14),'r','linewidth',1)
